package com.cqc.circledialog01;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.ListViewCompat;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.mylhyl.circledialog.CircleDialog;
import com.mylhyl.circledialog.callback.ConfigDialog;
import com.mylhyl.circledialog.callback.ConfigInput;
import com.mylhyl.circledialog.params.DialogParams;
import com.mylhyl.circledialog.params.InputParams;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

    private Context context = this;
    private ListViewCompat listView;
    private String[] items = {"相机", "相册"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListViewCompat) findViewById(R.id.listView);
        String[] titles = getResources().getStringArray(R.array.titles);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, titles);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);
    }

//                new CircleDialog.Builder(MainActivity.this);不能是ListActivity

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            case 0:
                new CircleDialog.Builder(MainActivity.this)
                        .setTitle("提示框")
                        .setText("text")
                        .setPositive("确定", null)
                        .show();
                break;
            case 1:
                new CircleDialog.Builder(MainActivity.this)
                        .setTitle("确定框")
                        .setText("text")
                        .setCancelable(false)
                        .setCanceledOnTouchOutside(false)
                        .setPositive("确定", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Toast.makeText(context, "确定框", Toast.LENGTH_SHORT).show();
                            }
                        })
                        .setNegative("取消", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Toast.makeText(context, "取消", Toast.LENGTH_SHORT).show();
                            }
                        })
                        .show();
                break;
            case 2://没有确定按钮
                new CircleDialog.Builder(MainActivity.this)
                        .setTitle("换头像")
                        .configDialog(new ConfigDialog() {
                            @Override
                            public void onConfig(DialogParams params) {
                                params.animStyle = R.style.dialogWindowAnim;
                            }
                        })
                        .setItems(items, new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                Toast.makeText(context, items[position], Toast.LENGTH_SHORT).show();

                            }
                        })
                        .setNegative("取消", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Toast.makeText(context, "取消", Toast.LENGTH_SHORT).show();
                            }
                        })
                        .show();
                break;
            case 3://输入框
                new CircleDialog.Builder(MainActivity.this)
                        .setTitle("输入框")
                        .setCancelable(false)
                        .setCanceledOnTouchOutside(false)
                        .configInput(new ConfigInput() {
                            @Override
                            public void onConfig(InputParams params) {

                            }
                        })
                        .setPositive("确定", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                            }
                        })
                        .setNegative("取消", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                            }
                        })
                        .show();
                break;
            case 4:
//djaj
                break;
            case 5:
//merge to dev
                break;
            case 6:
//git branch --set-upstream-to=origin/dev
                break;
            case 7:

                break;
        }
    }
}
